home *** CD-ROM | disk | FTP | other *** search
/ AI Game Programming Wisdom / AIGameProgrammingWisdom.iso / SourceCode / 11 Learning / 04 Mommersteeg / Penny / RandomPredictor.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-09-23  |  1.4 KB  |  36 lines

  1. //----------------------------------------------------------------------------------------------
  2. // Sequential Prediction Demo: The positioning pattern
  3. // 
  4. // Author:  Fri Mommersteeg
  5. // Date:    10-09-2001
  6. // File:    RandomPredictor.cpp
  7. //----------------------------------------------------------------------------------------------
  8.  
  9. //----------------------------------------------------------------------------------------------
  10. // Include files
  11. //----------------------------------------------------------------------------------------------
  12.  
  13. #include "stdafx.h"
  14. #include "randompredictor.h"
  15.  
  16. //----------------------------------------------------------------------------------------------
  17. // Setup(): sets up the random predictor (seeds the random number generator)
  18. //----------------------------------------------------------------------------------------------
  19.  
  20. void CRandomPredictor::Setup(int nAlphabetSize, unsigned int nSeed) {
  21.     m_nAlphabetSize = nAlphabetSize;
  22.     srand(nSeed);
  23. }
  24.  
  25. //----------------------------------------------------------------------------------------------
  26. // GetPrediction(): returns a random prediction
  27. //----------------------------------------------------------------------------------------------
  28.  
  29. bool CRandomPredictor::GetPrediction(int &Prediction) {
  30.  
  31.     Prediction = rand() % m_nAlphabetSize;
  32.  
  33.     // always assume that the prediction is good
  34.     return true;
  35. }
  36.